import numpy as np


# restore the image after model
def image_restore(i):
    i = i.to('cpu').clone().detach()
    i = i.numpy().squeeze()
    i = i.transpose(1, 2, 0)  # channel will be the first dimension after processing in the dataloader
    #i = i * np.array((0.229, 0.224, 0.225)) + np.array((0.485, 0.456, 0.406))  # because we used normalization before
    i = i.clip(0, 1)
    return i


# change numeric label to real names
def label2names(item):
    names = ['airplane',
             'automobile',
             'bird',
             'cat',
             'deer',
             'dog',
             'frog',
             'horse',
             'ship',
             'truck']
    dic_names = {i: names[i] for i in range(10)}
    return dic_names[item]


# not update some parameters of given model
def no_update(model):
    for param in model.parameters():
        param.requires_grad = False